import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Example {
    private final Lock lock = new ReentrantLock();
    private final Condition condition = lock.newCondition();

    public void awaitSignal() throws InterruptedException {
        lock.lock();
        try {
            condition.await(); // 使用条件变量等待信号代替 sleep()
        } finally {
            lock.unlock();
        }
    }

    public void signalAllWaitingThreads(){
        lock.lock();
        try{
            condition.signalAll(); // 发送通知唤醒所有等待中的线程
        }finally{
            lock.unlock();
        }
    }
}